[6.x] Move testing traits into Statamic\Testing\Concerns - #15115
Merged
Conversation
so addons using `AddonTestCase` can build users with and without a given permission, instead of hand-copying the trait. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`setTestUserGroups()` becomes `protected` to match the other concerns. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`FakeViewEngine`, `FakeViewFactory` and `FakeViewFinder` get their own files, so they're autoloadable rather than relying on the trait's file being loaded first. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
They're concrete classes, not traits, so they don't belong in `Concerns`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`FakeViewFactory` is constructed alongside the engine, so it can hold a reference directly instead of reaching through a generic container key that addons could collide with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request moves four test traits out of core's
Testsnamespace and intoStatamic\Testing\Concerns, so addons usingAddonTestCasecan use them too.Statamic's Control Panel routes are permission-guarded, so any addon testing them needs to build users with and without a given permission. Core already has exactly that helper in
tests/FakesRoles.php, but theTestsnamespace isn't autoloadable from an addon package — so addon authors end up hand-copying it.statamic/forms-procurrently carries a trimmed copy for its Slack connection tests, and can delete it once this lands.The traits that have moved:
FakesRolesFakesUserGroupsElevatesSessionsFakesViewsThis follows the same approach as
PreventsSavingStacheItemsToDiskin #9871 — the trait body moves tosrc/Testing/Concerns, and the file intestsbecomes a thin trait thatuses it. That keeps the 176 core test files importing these traits untouched.FakesViewsalso declaredFakeViewEngine,FakeViewFactoryandFakeViewFinderin the same file. They've each been given their own file, so they're autoloadable rather than relying on the trait's file having been loaded first.FakesUserGroups::setTestUserGroups()is nowprotectedrather thanprivate, to match the other concerns.No changes were needed to
AddonTestCase. It detectsPreventsSavingStacheItemsToDiskviaclass_uses_recursive()only because that trait needssetUp/tearDownhooks — none of these four do, so addons can justusethem directly.